home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / clonecd / September 93.img / Archives / Decoration / Screensavers / Screen Savers / TwilightZone / source / commands.c < prev    next >
Text File  |  1993-06-17  |  3KB  |  212 lines

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * Simple Sample Application Framework
  4.  *
  5.  * ©1991 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * commands.c -- called in response to menu commands or appleevents
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        11/6/91        1.0d1        initial coding
  14.  *
  15.  */
  16.  
  17. #include <Script.h>
  18.  
  19. #include "const.h"
  20. #include "strconst.h"
  21. #include "mymenus.h"
  22. #include "mytypes.h"
  23. #include "globals.h"
  24. #include "utils.h"
  25. #include "windowstuff.h"
  26.  
  27. #include "commands.h"
  28.  
  29. /* closes a window */
  30.  
  31. void CommCloseWindow(WindowPtr window)
  32. {
  33.     TInfoHndl infoHndl;
  34.     
  35.     if (!IsAppWindow(window))
  36.         return;
  37.     
  38.     infoHndl = GetWindowInfo(window);
  39.     
  40.     SendWindowMessage(window,kDeactivateMessage,nil);        
  41.     SendWindowMessage(window,kDestroyMessage,nil);
  42.     
  43.     DisposHandleChk(infoHndl);    
  44.     DisposeWindow(window);
  45. }
  46.  
  47.  
  48. /* processes edit menu commands */
  49.  
  50. void CommEdit(WindowPtr window,short command)
  51. {
  52.     short msg;
  53.     
  54.     if (!IsAppWindow(window))
  55.         return;
  56.  
  57.     switch (command) {
  58.         case kUndoItem:
  59.             msg = kUndoMessage;
  60.             break;
  61.         case kCutItem:
  62.             msg = kCutMessage;
  63.             break;
  64.         case kCopyItem:
  65.             msg = kCopyMessage;
  66.             break;
  67.         case kPasteItem:
  68.             msg = kPasteMessage;
  69.             break;
  70.         case kClearItem:
  71.             msg = kClearMessage;
  72.             break;
  73.         default:
  74.             return;
  75.     }
  76.     SendWindowMessage(window,msg,nil);
  77. }
  78.  
  79.  
  80. /* processes print commands */
  81.  
  82. void CommPrint(WindowPtr window)
  83. {
  84.     if (IsAppWindow(window))
  85.         SendWindowMessage(window,kPrintMessage,nil);
  86. }
  87.  
  88.  
  89. /* processes page setup commands */
  90.  
  91. void CommPageSetup(WindowPtr window)
  92. {
  93.     if (IsAppWindow(window))
  94.         SendWindowMessage(window,kPageSetupMessage,nil);
  95. }
  96.  
  97.  
  98. /* show about box */
  99.  
  100. void CommAbout(void)
  101. {
  102.     Alert(kAboutBoxDialog,nil);
  103. }
  104.  
  105.  
  106. /* new command */
  107.  
  108. void CommNew(void)
  109. {
  110. }
  111.  
  112.  
  113. /* open command */
  114.  
  115. void CommOpen(void)
  116. {
  117.     StandardFileReply sfReply;
  118.     SFTypeList typeList;
  119.     
  120.     typeList[0] = kAppType;
  121.     
  122.     StandardGetFile(nil,kNumAppTypes,typeList,&sfReply);
  123.     if (sfReply.sfGood) {
  124.         LoOpen(&sfReply.sfFile);
  125.     }
  126. }
  127.  
  128.  
  129. /* low-level open (can be called by aevt) */
  130.  
  131. void LoOpen(FSSpec *fSpec)
  132. {
  133.     WindowPtr window;
  134.     TInfoHndl info;
  135.     short wType;
  136.     OSErr err;
  137.     FInfo fInfo;
  138.     void *message;
  139.     
  140.     err = FSpGetFInfo(fSpec,&fInfo);
  141.     if (err!=noErr) {
  142.         DoError(err);
  143.         return;
  144.     }
  145.     
  146.     switch (fInfo.fdType) {
  147.         case kAppType:
  148.             wType = kDimmerWindow;
  149.             break;
  150.         default:
  151.             DoError(kInternalError);
  152.             return;
  153.     }
  154.     
  155.     window = MakeWindow(wType,nil,fSpec->name,true);
  156.  
  157.     if (window) {
  158.         info = GetWindowInfo(window);
  159.         BlockMove(fSpec,&(*info)->fileSpec,sizeof(FSSpec));
  160.         SendWindowMessage(window,kLoadMessage,message);
  161.     }
  162. }
  163.  
  164.  
  165. /* save command */
  166.  
  167. void CommSaveFile(WindowPtr window)
  168. {
  169.     TInfoHndl info;
  170.     
  171.     if (!IsAppWindow(window))
  172.         return;
  173.     
  174.     info = GetWindowInfo(window);
  175.     if (!(**info).changed)
  176.         return;
  177.         
  178.     if (!(**info).saved)
  179.         CommSaveAsFile(window);
  180.     else
  181.         LoSaveFile(window);
  182. }
  183.  
  184.  
  185. /* save as command */
  186.  
  187. void CommSaveAsFile(WindowPtr window)
  188. {
  189.     TInfoHndl info;
  190.     StandardFileReply sfReply;
  191.     OSErr err;
  192.     
  193.     if (!IsAppWindow(window))
  194.         return;
  195.     
  196.     info = GetWindowInfo(window);
  197.  
  198.     StandardPutFile(kPromptString,kDefaultFilename,&sfReply);
  199.     if (sfReply.sfGood) {
  200.         BlockMove(&sfReply.sfFile,&((**info).fileSpec),sizeof(FSSpec));
  201.         LoSaveFile(window);
  202.     }
  203. }
  204.  
  205.  
  206. /* low-level save file */
  207.  
  208. void LoSaveFile(WindowPtr window)
  209. {
  210.     SendWindowMessage(window,kSaveMessage,nil);
  211. }
  212.